/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Proyecto.graphicInterface;

import Proyecto.Logico.Logico;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JTextField;

/**
 *
 * @author LFBP
 */
public class Lienzo extends Canvas{
    
    private int i,n;
    private Logico logic;
    private JTextField txtCorX,txtCorY;
    
    public Lienzo(Logico logic,JTextField txtCorX,JTextField txtCorY){
        i = 0;
        n = 5;
        this.logic = logic;
        this.txtCorX = txtCorX;
        this.txtCorY = txtCorY;
        
        setBackground(Color.WHITE);
    }
    
     @Override
    public void paint(Graphics g) {
        g.clearRect(0, 0, size().width, size().height);
        
        for (int j = 0; j < 700; j += 30) {
        
            g.drawLine(j, 0,j ,510);
            if(j <= 510){
                g.drawLine(0, j,690 ,j);
                g.drawString(""+j, 5, j-1);
            }
            g.drawString(""+j, j+3, 10);
            
        }
        if(i > 0){
            int x = Integer.parseInt(txtCorX.getText());
            int y = Integer.parseInt(txtCorY.getText());
            g.drawLine(x-n, y-n, x+n, y+n);
            g.drawLine(x-n, y+n, x+n, y-n);           
        }
        
            
        
        i++;
        for (int j = 0; j < logic.getArray().size(); j++) {
            
            int s = (int)logic.verPunto(j, true);
            int d =  (int)logic.verPunto(j, false);
            
            g.drawLine(s-n, d-n, s+n, d+n);
            g.drawLine(s-n, d+n, s+n, d-n);
        }
        g.drawString("El promedio de los puntos es:" + logic.promedio(true)+ ","+ logic.promedio(false), 700, 30);
        g.drawString("El maximo punto X es:" + logic.max(true), 700, 50);
        g.drawString("El maximo punto Y es:" + logic.max(false), 700, 70);
        g.drawString("El minimo punto X es:" + logic.min(true), 700, 90);
        g.drawString("El minimo punto Y es:" + logic.min(false), 700, 110);
    }
    
}
